<?php
namespace App\Services\Factory;


use App\Common\Constant\Params;
use App\Services\Factory\Payment\Balance;
use App\Services\Factory\Payment\WxPay;

/**
 * 支付方式工厂
 * Class PaymentFactory
 * @package App\Services\Factory
 */
abstract class PaymentFactory
{

    private static $instance = [];

    public static function factory($payment_method)
    {
        if (empty(self::$instance[$payment_method])){
            switch ($payment_method){
                case Params::PAY_METHOD_WEIXIN:
                    $new = new WxPay;
                    break;
                case Params::PAY_METHOD_BALANCE:
                    $new = new Balance;
                    break;
                default:
                    $new = new VoidClass;
            }
            self::$instance[$payment_method] = $new;
        }
        return self::$instance[$payment_method];
    }

    /**
     * 生成支付表单
     * @param $order_number
     * @param $amount
     * @param $description
     * @param array $attach
     * @return mixed
     */
    abstract public function form($order_number,$amount,$redirect_url,$description,array $attach);

    /**
     * 接收&回应支付结果通知
     * @return $trade_number 商户系统的订单号，与请求一致,$payment_gate_number 微信支付订单号,$attach 商家数据包，原样返回
     */
    abstract public function notify();

    /**
     * 记录日志
     * @param $message
     * @return mixed
     */
    abstract public function log($message);

}